Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Creating a File Object

To access the data in a piece of storage that conforms to the 3DMF standard (such as a file on disk or a block of memory on the Clipboard), you need to create a new storage object, create a new file object, and attach the file object to the storage object. Thereafter, you can open the file object and read the data in it or write data to it. Listing 4 illustrates how to create storage and file objects and attach them to one another.

The MyGetInputFile function defined in Listing 4 calls the application- defined routine MyGetInputFileName to get the name of the disk file to open. Then it calls Q3FSSpecStorage_New to create a new storage object associated with that disk file and Q3File_New to create a new file object. If both creation calls complete successfully, MyGetInputFile calls Q3File_SetStorage to attach the file object to the storage object.

See the chapter "Storage Objects" for complete details on creating storage objects.

Listing 4 Creating a new file object

TQ3FileObject MyGetInputFile (void)
{
    TQ3FileObject           myFileObj;
    TQ3StorageObject        myStorageObj;
    OSType                  myFileType;
    FSSpec                  myFSSpec;
    if (MyGetInputFileName(&myFSSpec) == kQ3False)
        return(NULL);

    /*Create new storage object and new file object.*/
    if(((myStorageObj = Q3FSSpecStorage_New(&myFSSpec)) == NULL)
        || ((myFileObj = Q3File_New()) == NULL))
    {
        if (myStorageObj)
            Q3Object_Dispose(myStorageObj);
        return(NULL);
    }

    /*Set the storage for the file object.*/
    Q3File_SetStorage(myFileObj, myStorageObj);
    Q3Object_Dispose(myStorageObj);

    return (myFileObj);
}

Notice that the call to Q3File_SetStorage is followed immediately by a call to Q3Object_Dispose . The call to Q3File_SetStorage increases the reference count of the storage object, and the call to Q3Object_Dispose simply decreases that count.


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |